#include<bits/stdc++.h>
using namespace std;
#define int long long

struct node {
	string idNum;
	int chairNum;
} a[1005];

signed main() {
	int n;
	cin >> n;
	while (n--) {
		string s;
		int x, y;
		cin >> s >> x >> y;
		a[x] = {s, y};
	}

	int m;
	cin >> m;
	while (m--) {
		int x;
		cin >> x;
		cout << a[x].idNum << " " << a[x].chairNum << endl;
	}
	return 0;
}
